import TreeCesiumData from "./layer_tree_data";
import Environment from "../../utils/environment";
import LayerManager from "@/plugins/mev/layer/LayerManager";

class KMLData extends TreeCesiumData {
    constructor(data, viewer) {
        super(data, viewer);
        this._DataObject = null;
        /* this._kml = null;*/
        this._data = data;
        this._viewer = viewer;
    }

    show() {
        let that = this;
        if (this._DataObject == null) {
            let promise = Cesium.KmlDataSource.load(this._data.path, {
                /* let promise = Cesium.KmlDataSource.load(Environment.getDataBasePath() + that._data.path, {*/
                camera: this._viewer.scene.camera,
                canvas: this._viewer.scene.canvas
            });
            promise.then(function(dataSource) {
                that._DataObject = dataSource;
                that._viewer.dataSources.add(dataSource);
                let entities = dataSource.entities.values;
                for (let i = 0; i < entities.length; i++) {
                    let entity = entities[i];
                }
              /*  that.flyTo(that._DataObject);*/
            });
        }
    }

    close() {
        if (this._DataObject) {
            if (this._viewer.dataSources.contains(this._DataObject)) {
                this._viewer.dataSources.remove(this._DataObject);
            }
            this._DataObject = null;
        }
    }

    setProperties(props) {}
}

export default KMLData;
